package com.sc.server.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration      //让Spring来加载该类配置
@EnableSwagger2     //启用Swagger2
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("架构设计 系统管理 RESTful APIs,项目前缀 system")).select()
                //扫描指定包中的swagger注解
                //.apis(RequestHandlerSelectors.basePackage("com.xia.controller"))
                //扫描所有有注解的api，用这种方式更灵活
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build()
                .groupName("all全部接口");
    }

    @Bean
    public Docket restApi4() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("系统配置conf模块 RESTful APIs")
                .apiInfo(apiInfo("conf模块,项目前缀 system"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sc.server.system"))
                .paths(PathSelectors.regex("/conf/.*"))
                .build();
    }
    @Bean
    public Docket restApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("权限模块 RESTful APIs")
                .apiInfo(apiInfo("权限(auth)模块接口,项目前缀system"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sc.server.system"))
                .paths(PathSelectors.regex("/auth/.*"))
                .build();
    }
    private ApiInfo apiInfo(String title) {
        return new ApiInfoBuilder()
                .title(title)
                .contact("金马测控")
                .version("1.0.0")
                .build();
    }
}
